<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/vectrics.tld"    prefix="vectrics" %>

<%@ page import="org.vectrics.struts.*" %>
<%@ page import="org.vectrics.hibernate.ThreadProperties" %>
<%@ page import="org.vectrics.recruiter.struts.admin.AdminPersonProfileForm" %>
<%@ page import="org.vectrics.recruiter.job.JobTerm" %>
<%@page import="org.vectrics.location.Location"%>
<%@page import="org.vectrics.recruiter.RecruitServiceLocator"%>
<%@page import="org.vectrics.recruiter.job.Job"%>
<%@page import="java.util.List"%>

<%
	String newPersonValue = request.getParameter("newUser");

	if ((newPersonValue == null) || (newPersonValue.length() == 0)) {
		newPersonValue = (String)request.getAttribute("newUser");
	}

	if ((newPersonValue == null) || (newPersonValue.length() == 0)) {
		newPersonValue = request.getParameter("newPerson");
	}
	String userId = request.getParameter("userId");

	if (userId == null)
		userId = request.getParameter("user");


	String domainId = ThreadProperties.getDomain().getId().toString();
	
	//Recupero los paises
	List<Location> countries = RecruitServiceLocator.getPersonService().findCountryLocation();
	//seteo la request de los paises 
	request.setAttribute("countries", countries);
	
	// id de company
	String companyId = ThreadProperties.getDomain().getPrimaryCompany().getId().toString();
	// Recupero la lista de Jobs
	List<Job> jobs = RecruitServiceLocator.getJobProvider().findJobsForCompanyExcludeFillAndCancelled(new Long(companyId));
		
	//seteo la request
	request.setAttribute("jobs", jobs);
	
	//Busco la function si fue seteada
	String function="";
	if (request.getAttribute("function")!=null) {
		function = request.getAttribute("function").toString();
	} else {
		function = "Otro";
	}

	// Recupero los status del empleado
	List<JobTerm> status = RecruitServiceLocator.getJobProvider().findAllJobTerm();
	// Seteo la request de los status 
	request.setAttribute("status", status);
%>
<script type="text/javascript">

	function changeCondition(element) {
		var divEmployee = document.getElementById('divEmployee');
		var comboJob = document.getElementById('jobCandidate');
		// si es none ocultamos y deshabilitamos
		if (element.value == 'n') {
			divEmployee.style.display = "none";
			comboJob.disabled = true;
		} else if (element.value == 'c') {
			divEmployee.style.display = "none";
			comboJob.disabled = false;
		} else if (element.value == 'e') {
			divEmployee.style.display = "";
			comboJob.disabled = true;
		}
	}

</script>

<script type="text/javascript" src="/hrs-intranet/js/utils.js">  </script>


<jsp:useBean id="profileForm" class="org.vectrics.recruiter.struts.admin.AdminPersonProfileForm" scope="request"/>

<vectrics:errors/>

<html:form action="/admin/user/person/save" method="POST" focus="lastName">
	<html:hidden property="userId"/>
	<html:hidden property="companyId"/>
	<input type="hidden" name="newPerson" value="<%=newPersonValue%>">
	<table>
		<tr>
			<td width="50%">
				<table cellpadding="4" cellspacing="1">
					<tr>
						<td class="formBg1" valign="middle">
							<font class="formLabelClass"><bean:message key="prompt.last.name"/><b> *</b></font>
							<vectrics:errors property="lastName"/>
						</td>
						<td class="formBg1" valign="top">
							<html:text property="lastName" styleClass="formEditClass" maxlength="20"/>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg2" valign="middle">
							<font class="formLabelClass"><bean:message key="prompt.first.name"/><b> *</b></font>
							<vectrics:errors property="firstName"/>
						</td>
						<td class="formBg2" valign="top">
							<html:text property="firstName" styleClass="formEditClass" maxlength="20"/>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle">
							<font class="formLabelClass"><bean:message key="prompt.middle.name"/></font>
							<vectrics:errors property="middleName"/>
						</td>
						<td class="formBg1" valign="top">
							<html:text property="middleName" styleClass="formEditClass" maxlength="20"/>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle">
							<font class="formLabelClass"><bean:message key="prompt.previous.last.name"/></font>
							<vectrics:errors property="previousLastName"/>
						</td>
						<td class="formBg1" valign="top">
							<html:text property="previousLastName" styleClass="formEditClass" maxlength="20"/>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg2" valign="middle">
							<font class="formLabelClass"><bean:message key="prompt.name.known.as"/></font>
						</td>
						<td class="formBg2" valign="top">
							<html:text property="knownAs" styleClass="formEditClass" maxlength="20"/>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.name.prefix"/></font></td>
						<td class="formBg1" valign="top">
						    <html:text styleClass="formEditClass" property="prefix" maxlength="10" />
                        </td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.name.birthday"/><b> *</b></font></td>
						<td class="formBg1" valign="top">						
							<html:text styleClass="formButton" property="birthday" maxlength="10" styleId="birthday" />
							<input type="button" id="birthdayBt" name="birthdayBt" value="..." /> 
										<script type="text/javascript">
										Calendar.setup(
												{
  												inputField  : "birthday",         // ID of the input field
  												ifFormat    : "%d/%m/%Y",    // the date format
  												button      : "birthdayBt"       // ID of the button
												}
										);
										</script>
						</td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.birthCountry"/></font></td>
						<td class="formBg1" valign="top">
							<html:select property="birthCountry" styleClass="formComboClass">
								<html:option value=""></html:option>
								<html:options
										collection="countries"
										labelProperty="name"
										property="id"
								/> 
							</html:select>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg2" valign="middle"><font class="formLabelClass"><bean:message key="prompt.marital.status"/></font></td>
						<td class="formBg2" valign="top">
							<html:select property="maritalStatus" styleClass="formComboClass" >
								<html:option value="d"><bean:message key="prompt.divorced"/></html:option>
								<html:option value="m"><bean:message key="prompt.married"/></html:option>
								<html:option value=""><bean:message key="prompt.not.given"/></html:option>
								<html:option value="s"><bean:message key="prompt.not.married"/></html:option>
							</html:select>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.gender"/><b> *</b></font></td>
						<vectrics:errors property="gender"/>
						<td class="formBg1" valign="top">
							<html:select property="gender" styleClass="formComboClass">
								<html:option value="f"><bean:message key="prompt.female"/></html:option>
								<html:option value="m"><bean:message key="prompt.male"/></html:option>
							</html:select>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg2" valign="middle"><font class="formLabelClass"><bean:message key="prompt.primary.email"/><b> *</b></font></td>
						<td class="formBg2" valign="top">
						     <html:text styleClass="formEditClass" property="email" maxlength="80"/>
                        </td>						
						<td></td>
					</tr>
					<tr>
						<td class="formBg2" valign="middle"><font class="formLabelClass"><bean:message key="prompt.primary.email.format"/><b> *</b></font></td>
						<td class="formBg2" valign="top">
							<html:select property="emailFormat" styleClass="formComboClass">
								<html:option value="html"><bean:message key="prompt.primary.email.format.html"/></html:option>
								<html:option value="text"><bean:message key="prompt.primary.email.format.text"/></html:option>
							</html:select>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle">
							<font class="formLabelClass"><bean:message key="prompt.secondary.email"/></font>
						</td>
						<td class="formBg1" valign="top">
							<html:text property="email2" styleClass="formEditClass" maxlength="80"/>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.primary.email.format.2"/><b> *</b></font></td>
						<td class="formBg1" valign="top">
							<html:select property="emailFormat2" styleClass="formComboClass">
								<html:option value="html"><bean:message key="prompt.primary.email.format.html"/></html:option>
								<html:option value="text"><bean:message key="prompt.primary.email.format.text"/></html:option>
							</html:select>
						</td>
						<td></td>
					</tr>
					
					<tr>
						<td class="formBg2" valign="middle"><font class="formLabelClass"><bean:message key="prompt.work.phone"/></font></td>
						<td class="formBg2" valign="top">
							<html:text property="workPhone" styleClass="formEditClass" maxlength="30"/>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.home.phone"/></font></td>
						<td class="formBg1" valign="top">
							<html:text property="homePhone" styleClass="formEditClass" maxlength="30"/>
						</td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg2" valign="middle"><font class="formLabelClass"><bean:message key="prompt.mobile.phone"/></font></td>
						<td class="formBg2" valign="top">
						    <html:text styleClass="formEditClass" property="cellPhone" maxlength="30"/>
                        </td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.person.cuilOrCuit"/><b> *</b></font></td>
						<td class="formBg1" valign="top">
							<html:text styleClass="formEditClass" property="cuilOrCuit" maxlength="15" />
						</td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.emergency.contact"/></font></td>
						<td class="formBg1" valign="top">
							<html:text styleClass="formEditClass" property="emergencyContactName" maxlength="100" />
						</td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.emergency.phone"/></font></td>
						<td class="formBg1" valign="top">
							<html:text styleClass="formEditClass" property="emergencyContactPhoneNumber" maxlength="30" />
						</td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass">Programming Language</font></td>
						<td class="formBg1" valign="top">
							<html:select property="programmingLanguage" styleClass="formComboClass" >
								<html:option value="Net">.NET</html:option>
								<html:option value="Java">Java</html:option>
								<html:option value="Otro">Otro</html:option>
								<html:option value="NoAplica">No Aplica</html:option>
							</html:select>
						</td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass">English Level</font></td>
						<td class="formBg1" valign="top">
							<html:select property="englishLevel" styleClass="formComboClass">
								<html:option value="ELEMENTAL">Elemental</html:option>
								<html:option value="PRE_INTERMEDIO">Pre-intermedio</html:option>
								<html:option value="INTERMEDIO">Intermedio</html:option>
								<html:option value="INTERMEDIO_AVANZADO">Intermedio-Avanzado</html:option>
								<html:option value="AVANZADO">Avanzado</html:option>
								<html:option value="NO_APLICA">No Aplica</html:option>
							</html:select>
						</td>
					</tr>
					<tr>
						<td valign="TOP" colspan="3"><br><h3><bean:message key="heading.home.address"/></h3></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.street.address"/> <b>*</b> </font></td>
						<td class="formBg1" valign="top">
						      <html:text styleClass="formEditClass" property="homeAddress1" maxlength="80" />
                        </td>
						<td></td>
					</tr>
					<tr> 
						<td class="formBg1" valign="middle">
							<font class="formLabelClass"><bean:message key="prompt.city"/> <b>*</b> </font>
						</td>
						<td class="formBg1" valign="top">
                            <vectrics:locationPicker 
                                   typeCode="candidate.location"
                                   caption="prompt.city" 
                                   paramName="location" 
                                   popupLeft="200" 
                                   popupTop="480" 
                                   styleClase="formStaticClass"
                                   canSelecction="state" />
                        </td>
						<td></td>
					<tr>
						<td class="formBg1" valign="middle"><font class="formLabelClass"><bean:message key="prompt.postal.code"/></font></td>
						<td class="formBg1" valign="top">
						     <html:text styleClass="formEditClass" property="homeZip" maxlength="15" />
                        </td>
						<td></td>
					</tr>	
<%	if (newPersonValue != null) {	%>	
					<tr>
						<td></td>
						<td></td>
					</tr>
                 </table>
                 <table cellpadding="4" cellspacing="1" width="80%" >
					<tr>
						<td><h2><bean:message key="prompt.person.condition"/></h2></td>
						<td></td>
					</tr>
					<tr>
						<td class="formBg1" valign="middle">
							<html:radio property="condition" value="n" onclick="changeCondition(this);" styleId="condition">
								<font class="formLabelClass"><bean:message key="prompt.person.condition.none"/></font>
							</html:radio>
							<br />
							<html:radio property="condition" value="c" onclick="changeCondition(this);" styleId="condition">
								<font class="formLabelClass"><bean:message key="prompt.person.condition.candidate"/></font>
							</html:radio>
							<html:select property="jobCandidate" styleClass="formComboClass" styleId="jobCandidate" disabled="true">
								<html:options collection="jobs" labelProperty="title" property="id" />
							</html:select>
							<br />
							<html:radio property="condition" value="e" onclick="changeCondition(this);" styleId="condition">
								<font class="formLabelClass"><bean:message key="prompt.person.condition.employee"/></font>
							</html:radio>
                            <br />
                            <br />
							<div id="divEmployee" style="display: none;">
								<table>
									<tr>
										<td class="formBg1" valign="middle"><font class="subFont">
											<bean:message key="prompt.employee.condition"/><b> *</b></font>
										</td>
										<td class="formBg1" valign="top">
											<html:select property="status" styleClass="formComboClass">
												<html:options collection="status" labelProperty="description" property="code"/>
											</html:select>
										</td>
										<td></td>
									</tr>																		
									<tr>
										<td class="formBg1" valign="middle">
											<font class="subFont"><bean:message key="prompt.employee.date.start"/><b>*</b></font>
										<vectrics:errors property="dateStart" />
										</td>
										<td class="formBg1" valign="top">
											<html:text property="dateStart" styleClass="formButton" styleId="dateStart" />
											<input type="button" id="dateStartBt" name="dateStartBt" value="..." /> 
														<script type="text/javascript">
				  												Calendar.setup(
				    												{
				      												inputField  : "dateStart",         // ID of the input field
				      												ifFormat    : "%d/%m/%Y",    // the date format
				      												button      : "dateStartBt"       // ID of the button
				    												}
				  												);
														</script>
										</td>
									</tr>
									<tr>
										<td class="formBg1" valign="middle">
											<font class="subFont">
												<bean:message key="prompt.employee.function"/> <b>*</b>
											</font>
										</td>
										<td class="formBg1" valign="top">
											<vectrics:jobFunctionCombo property="function" value="<%= function %>" />
										</td>
									</tr>
									
									<tr> 
										<td class="formBg1" valign="middle">
											<font class="formLabelClass"><bean:message key="prompt.employee.career.rolePosition"/> <b>*</b> </font>
										</td>
										<td class="formBg1" valign="top">
											<html:text styleClass="formButton" maxlength="3" property="careerRolePosition" onkeypress="return soloNumerosConNegativos(event,this);" /><font class="formLabelClass">&nbsp; %</font>
                        				</td>
									</tr>

									<tr> 
										<td class="formBg1" valign="middle">
											<font class="formLabelClass"><bean:message key="prompt.employee.hoursPerDay"/> <b>*</b> </font>
										</td>
										<td class="formBg1" valign="top">
											<html:text styleClass="formButton"  maxlength="5" property="hoursPerDay" onkeypress="return soloNumeros(event,this);" />
                        				</td>
									</tr>

									<tr> 
										<td class="formBg1" valign="middle">
											<font class="formLabelClass"><bean:message key="prompt.employee.office.location"/> <b>*</b> </font>
										</td>
										<td class="formBg1" valign="top">
                            				<vectrics:locationPicker 
                                   				typeCode="job.location"
                                   				caption="prompt.city" 
                                   				paramName="officeLocation" 
                                   				popupLeft="200" 
                                   				popupTop="780" 
                                   				styleClase="formStaticClass"
                                   				canSelecction="state" />
                        				</td>
									</tr>

									<tr> 
										<td class="formBg1" valign="middle">
											<font class="formLabelClass"><bean:message key="prompt.employee.mentor"/> </font>
										</td>
										<td class="formBg1" valign="top">
											<vectrics:personPicker 
												remoteMethod="get.matching.employee"
												contextPath="/hrs-intranet"
												caption="Mentor"
												paramName="idMentor"
												popupLeft="200"
												popupTop="780"
												styleClase="formStaticClass"/>
                        				</td>
									</tr>
									
									<!--Agrego pedido por bug HRS-768-->
									<tr>
				                       <td class="formBg1" valign="middle">
				                           <font class="formLabelClass"><bean:message key="prompt.employee.medical.Insurance"/></font>
				                       </td>
				                       <td class="formBg1" valign="top">
				                       		<html:text styleClass="formLabelClass"  maxlength="50" property="medicalInsurance"/>
				                       </td>
				                    </tr>

									<tr>
										<td class="formBg1" valign="top">
											<font class="subFont"><bean:message key="prompt.employee.hiring.notes"/></font>
										</td>
										<td class="formBg1" valign="top">
											<html:textarea property="hiringNote" 
											               styleClass="formTextAreaClass" 
											               rows="8" cols="60"  />
										</td>
									</tr>
								</table>
							</div> <!-- end divEmployee -->
						</td>
						<td></td>
					</tr>
<%	}	 %>
					<tr>
						<td valign="TOP" align="center" colspan="3">
							<vectrics:formButton elementId="ok.btn" code="button.ok" phraseCode="button.ok" value="submit" name="submit"/>&nbsp;
							<vectrics:formButton elementId="cancel.btn" code="button.cancel" phraseCode="button.cancel" value="cancel" name="cancel"/>
						</td>
					</tr>
				</table>
			</td>
			
		</tr>
	</table>
	
</html:form>
<script type="text/javascript">
	// para que se inicialicen las opciones
	var radios = document.getElementsByTagName('input');
	for (a=0; a<radios.length; a++) {
		if ((radios[a].type == "radio") && (radios[a].checked)) {
			changeCondition(radios[a]);
			break;
		}
	}
</script>